﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace T2CalcLib
{
    public class Production
    {
        public Int64 TypeID { get; set; }
        public String TypeName { get; set; }

        public Int32 AmountPerRun { get; set; }
        public Int32 RunPerBPC { get; set; }
        public Int32 BaseWaste { get; set; }

        public Dictionary<Material, Decimal> MaterialsAndAmount { get; set; }
        public List<Material> MaterialExtras { get; set; }

        public Int32 MaterialEfficiency { get; set; }

        public void RecalculateMatrialAmount()
        {
            foreach (var item in this.MaterialsAndAmount.Select(x => x.Key).ToList())
            {
                Decimal waste;
                if (this.MaterialEfficiency < 0)
                {
                    waste = Math.Round(
                        (Decimal)item.Amount
                        * ((Decimal)this.BaseWaste / 100)
                        * (1 - (Decimal)this.MaterialEfficiency)
                        , 0, MidpointRounding.AwayFromZero);
                    this.MaterialsAndAmount[item] = item.Amount + (Int32)waste;
                }
                else
                {
                    waste = Math.Round(
                        (Decimal)item.Amount
                        * ((Decimal)this.BaseWaste / 100)
                        * (1 / ((Decimal)this.MaterialEfficiency + 1))
                        , 0, MidpointRounding.AwayFromZero);
                    this.MaterialsAndAmount[item] = item.Amount + (Int32)waste;
                }
                
            }
        }
    }
}
